package com.powernode.mapper;

import com.powernode.domain.Prod;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 * 商品 Mapper 接口
 * </p>
 *
 * @author 付作巍
 * @since 2024-08-17
 */
public interface ProdMapper extends BaseMapper<Prod> {
    /**
     * 修改商品prod库存数量
     * @param prodId 商品标识
     * @param count 数量
     * @param version 版本
     * @return
     */
    @Update("update prod set sold_num = sold_num - #{count},total_stocks = total_stocks + #{count},version = version + 1 where prod_id = #{prodId} and version = #{version} and (total_stocks = total_stocks + #{count})>=0")
    Integer updateProdStock(@Param("prodId") Long prodId, @Param("count") Integer count, @Param("version") Integer version);
}
